package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Number           string `gorm:"column:number;type:varchar(30);not null;index;comment:号码"`
	Password         string `gorm:"type:varchar(255);not null;comment:密码"`
	Salt             string `gorm:"type:varchar(255);not null;comment:盐"`
	MemberExpireTime int64  `gorm:"type:int;not null;comment:会员过期时间"`
	Status           int    `gorm:"type:int;not null;comment:状态"`
}

// 套餐表
type Member struct {
	gorm.Model
	Name     string  `gorm:"type:varchar(30);not null;comment:'会员种类：月，季，年'"`
	Price    float64 `gorm:"type:decimal(10,2);not null;default:0;comment:'会员价格'"`
	Types    int     `gorm:"type:int;not null;comment:'会员类型'"`
	Duration int     `gorm:"type:int;not null;comment:'会员时长'"`
}

// 订单表
type Order struct {
	gorm.Model
	OrderNo  string  `gorm:"type:varchar(64);uniqueIndex;not null;comment:'订单号'"`      // 唯一订单号
	UserID   uint    `gorm:"type:int;not null;index;comment:'用户ID'"`                    // 用户ID
	MemberID uint    `gorm:"type:int;not null;index;comment:'会员套餐ID'"`                // 会员套餐ID
	Amount   float64 `gorm:"type:decimal(10,2);not null;default:0;comment:'订单金额'"`    // 金额
	PayType  int64   `gorm:"type:int;not null;comment:'支付方式(1支付宝,2微信,3QQ支付)'"` // 支付渠道
	Status   int     `gorm:"type:int;default:0;comment:'订单状态:0待支付,1已支付,2失败'"` // 订单状态
}

type Recharge struct {
	gorm.Model
	OrderNo  string  `gorm:"type:varchar(50);not null;index;comment:'订单号'"`
	UserID   uint    `gorm:"type:int;not null;index;comment:'用户ID'"`
	QQNumber string  `gorm:"type:varchar(30);not null;comment:'qq号'"`
	MemberID uint    `gorm:"type:int;not null;comment:'会员套餐ID'"`
	PayType  int64   `gorm:"type:int;not null;comment:'支付类型:1支付宝,2微信'"`
	Amount   float64 `gorm:"type:decimal(12,2);not null;comment:'充值金额'"`
	Status   int     `gorm:"type:int;not null;default:0;comment:'充值状态, 0待支付, 1已支付'"`
}

func (r *Recharge) Creat(db gorm.DB) error {
	return nil
}

func (u *User) UpdateMemberTime(db gorm.DB, userId, memberExpireTime int) error {
	return db.Model(&User{}).Where("id = ?", userId).Update("member_expire_time", memberExpireTime).Error
}
